<template>
  <div class="datail">
    <van-cell-group>
      <van-field v-model="value" placeholder="请输入商品名称" />
    </van-cell-group>
    <van-button type="info" size="large" @click="addGoods">添加商品</van-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      value: ''
    }
  },
  methods: {
    async addGoods() {
      const { data: res } = await this.$http.post('/api/addproduct', {
        name: this.value
      })
      if (res.status !== 0) {
        return this.$toast.fail('添加失败')
      }
      this.$toast.success('添加成功！')
      this.$router.push('/search')
    }
  }
}
</script>

<style lang="less" scoped>
.van-button {
  height: 40px;
  background: #1989fa;
  border: 1px solid #1989fa;
  line-height: 38px;
  margin: 40px 0;
}
</style>
